package algorithm;
import java.util.Iterator;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2022-02-17
 * Time: 19:12
 */
public class SequenceList<T> {
    private T[] eles;
    private int N;
    public SequenceList(int capacity){
        this.eles=(T[])new Object[capacity];
        this.N=0;
    }
    public void clear(){
        this.N=0;
    }
    public boolean isEmpty(){
        return N==0;
    }
    public int length(){
        return N;
    }
    public T get(int i){
        return eles[i];
    }
    public void insert(T t){
        eles[N++]=t;
    }
    public void insert(int i,T t){
        for(int index=N-1;index>i;index--){
            eles[index]=eles[index-1];
        }
        eles[i]=t;
    }
    public T remove(int i){
        T current=eles[i];
        for(int index=i;index<N-1;index++){
            eles[index]=eles[index+1];
        }
        N--;
        return current;
    }
    public int indexOf(T t){
        for(int i=0;i<N;i++){
            if(eles[i].equals(t)){
                return i;
            }
        }
        return -1;
    }

}
